package Registration;

import java.sql.ResultSet;
import dbmanager.DBManager;
import dbmanager.GetIdName;

public class DeleteMasterType
{
	String TypeValue;
	DBManager db = new DBManager();
	GetIdName gin;
	String Type = "type";
	public DeleteMasterType(String TypeValue) 
	{
		db.getConnect();
		gin = new GetIdName(db);
		Type = gin.getId(Type);
		this.TypeValue = gin.getId(TypeValue);
	}
	
	public int Delete()
	{
		int Count=0;
		try 
		{
			ResultSet rs = db.getSelect("select mid from property_details where pid="+Type+" and pv="+TypeValue);
			while(rs.next())
			{
				try
				{
					String mid = rs.getString("mid");
					db.getDelete("delete from property_details where mid = "+mid);
					db.getDelete("delete from master_table where id = "+mid);
					Count++;
				} 
				catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		} 
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return Count;
	}
	public static void main(String[] args) 
	{
		DeleteMasterType del = new DeleteMasterType("Item");
		System.out.println(del.Delete()+" Masters are Deleted");
	}
}
